<template>
  <div>
    <a-table
      rowKey="id"
      :columns="columns"
      :pagination="false"
      size="small"
      :data-source="dataSource"
      :row-selection="{ onChange: onSelectChange, type: 'radio', selectedRowKeys: selectedRowKeys }"
    >
    </a-table>
    <div style="margin: 8px 0px">根据历史项目创建</div>
    <a-table
      rowKey="id"
      :columns="historyColumns"
      :pagination="false"
      size="small"
      :data-source="historyDataSource"
      :row-selection="{ onChange: onSelectHistoryChange, type: 'radio', selectedRowKeys: selectedRowKeys }"
    >
    </a-table>
  </div>
</template>
<script>
import { getAction } from '@/api/manage'

const columns = [
  {
    title: '方案名称',
    dataIndex: 'name',
    key: 'name',
    width: 200,
  },
  {
    title: '方案版本',
    dataIndex: 'version',
    key: 'version',
  },
  {
    title: '类别名称',
    dataIndex: 'type',
    key: 'type',
    ellipsis: true,
  },
  {
    title: '子类别名称',
    dataIndex: 'cate',
    key: 'cate',
    ellipsis: true,
  },
  {
    title: '编制人',
    dataIndex: 'createBy',
    key: 'createBy',
    ellipsis: true,
  },
  {
    title: '编制日期',
    dataIndex: 'createTime',
    key: 'createTime',
    ellipsis: true,
  },
]
// name ，extType，extStage，extMechanism
const historyColumns = [
  {
    title: '项目名称',
    dataIndex: 'name',
    key: 'name',
  },
  {
    title: '项目类别',
    dataIndex: 'extType',
    key: 'extType',
  },
  {
    title: '项目被审计单位',
    dataIndex: 'extMechanism',
    key: 'extMechanism',
  },
  {
    title: '阶段',
    dataIndex: 'extStage',
    key: 'extStage',
  },
]
export default {
  name: 'tempList',
  components: {},
  data() {
    return {
      columns,
      historyColumns,
      selectedRowKeys: ['1'],
      dataSource: [],
      historyDataSource: [],
      url: {
        list: '/sjxmzygl/sjWorkZtfa/getProTemplatOrDept',
        historyData: '/sjxmzygl/sjWorkZtfa/getHistoryProject',
      },
    }
  },
  watch: {},
  created() {
    this.getList()
    this.getHistoryData()
  },
  methods: {
    onSelectChange(selectedRowKeys, selectedRow) {
      this.selectedRowKeys = selectedRowKeys
      this.$emit('getRadio', selectedRowKeys[0], selectedRow[0])
    },
    onSelectHistoryChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
      this.$emit('getHistoryRadio', selectedRowKeys[0])
    },
    getList() {
      getAction(this.url.list).then((res) => {
        if (res.success) {
          this.dataSource = res.result.records || res.result
          this.$emit('getRadio', this.dataSource[0].id, this.dataSource[0])
        }
      })
    },
    getHistoryData() {
      getAction(this.url.historyData).then((res) => {
        if (res.success) {
          this.historyDataSource = res.result.records || res.result
        }
      })
    },
  },
}
</script>

<style lang='less' scoped>
</style>
